package wjh.listenner;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import wjh.mapper.DoctorMapper;
import wjh.pojo.Records;

import javax.print.Doc;
import java.util.ArrayList;
import java.util.List;

/**
 * 功能
 * 作者：lyh
 * 日期：2024/9/12 15:09
 * 导入须创建监听器
 */
@Component
public class RecordsListenner extends AnalysisEventListener<Records> {
    @Autowired
    private DoctorMapper doctorMapper;
    //创建集合保存重复元素
    private static List<Records> list = new ArrayList<>();
    public static List<Records> getList(){
        return list;
    }
    @Override
    public void invoke(Records records, AnalysisContext analysisContext) {
        //根据id查找
        Records records1 =doctorMapper.findRecordById(records.getId());
        //已经有的添加到list
        if (records1!=null){
            list.add(records1);
        }
        //没有数据 添加到数据库
        else {
            doctorMapper.addRecords(records);
        }
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
